package com.gree.scmservice.controller;

import com.alibaba.fastjson.JSONObject;
import com.gree.common.annotation.Log;
import com.gree.common.entity.ReturnVo;
import com.gree.common.entity.SysApiRoleVo;
import com.gree.common.enums.BusinessType;
import com.gree.common.service.SysApiRoleService;
import com.gree.scmservice.service.GscmSysRoleApiService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.UUID;

/**
 * 接口管理
 * Created by 180686 on 2021/02/17 14:48
 */

@RestController
@RequestMapping("/sysapirole")
@Api(tags = "系统信息:接口管理接口")
public class SysApiRoleController {

    @Autowired
    private SysApiRoleService sysApiRoleService;

    @Autowired
    private GscmSysRoleApiService gscmSysRoleApiService;

    /**
     * 接口管理页面展示
     * @param jsonObject
     * @return
     */
    @PostMapping("/display")
    @ApiOperation(value = "接口管理页面展示")
    @ApiImplicitParam(name = "logininfor", value = "用户登录日志", dataType = "SysLogininfor")
    public Object display(@RequestBody JSONObject jsonObject){
        return new ReturnVo<>("200","success",gscmSysRoleApiService.displaySysApiRole(jsonObject));
    }

    /**
     * 接口管理插入功能
     * @param sysApiRoleVo
     * @return
     */
    @Log(title = "接口管理日志", businessType = BusinessType.INSERT)
    @PostMapping("/insert")
    @ApiOperation(value = "接口管理插入功能")
    @ApiImplicitParam(name = "sysApiRoleVo", value = "接口信息", dataType = "SysApiRoleVo")
    public Object insert(@Validated @RequestBody SysApiRoleVo sysApiRoleVo){
        return gscmSysRoleApiService.insertSysApiRole(sysApiRoleVo);
    }

    /**
     * 接口管理修改功能
     * @param sysApiRoleVo
     * @return
     */
    @Log(title = "接口管理日志", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    @ApiOperation(value = "接口管理修改功能")
    @ApiImplicitParam(name = "sysApiRoleVo", value = "接口管理修改功能", dataType = "SysApiRoleVo")
    public Object update(@Validated @RequestBody SysApiRoleVo sysApiRoleVo){
        return gscmSysRoleApiService.updateSysApiRole(sysApiRoleVo);
    }

    /**
     * 接口管理删除功能
     * @param infoIds
     * @return
     */
    @Log(title = "接口管理日志", businessType = BusinessType.UPDATE)
    @DeleteMapping("/{infoIds}")
    @ApiOperation(value = "接口管理删除功能")
    @ApiImplicitParam(name = "infoIds", value = "接口信息ID", dataType = "Long[]")
    public Object remove(@PathVariable Long[] infoIds){
        return gscmSysRoleApiService.deleteApiRoleByIds(infoIds);
    }

    /**
     * 接口管理清除缓存功能
     * @return
     */
    @Log(title = "接口管理日志", businessType = BusinessType.CLEAN)
    @DeleteMapping("/clearCache")
    @ApiOperation(value = "接口管理清除缓存功能")
    public Object clearCache(){
        sysApiRoleService.clearCache();
        return new ReturnVo("200","success");
    }

    /**
     * 接口管理生成token功能
     * @return
     */
    @GetMapping("/createuuid")
    @ApiOperation(value = "接口管理生成token功能")
    public Object createuuid(){
        String uuid = UUID.randomUUID().toString();
        return new ReturnVo("200","success",uuid);
    }


}
